package com.example.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.entity.Role;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
* @author circle48
* @description 针对表【role(角色表)】的数据库操作Mapper
* @createDate 2024-04-26 16:01:15
* @Entity generator.domain.Role
*/
public interface RoleMapper extends BaseMapper<Role> {
    /**
     * 根据角色ID返回权限列表
     * @param roleIds
     * @return 权限列表
     */
    List<String> getPermissionsByRoleIds(@Param("roleIds") List<Long> roleIds);

    @Insert("insert into user_role(user_id, role_id) values(#{userId},2)")
    void insertDefaultRole(@Param("userId") Long userId);

    @Select("SELECT r.rolename FROM role r JOIN user_role ur ON r.id = ur.role_id " +
            "WHERE ur.user_id = #{userId}")
    String getRoleName(Long userId);
}




